package com.charonmc.listeners;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.player.PlayerInteractEvent;

public class GeneralItemListener implements Listener {
    @EventHandler
    public void onPlayerUseGeneralItem(PlayerInteractEvent event){
        if (event.getItem() != null && event.getItem().getItemMeta().getDisplayName() != null){
            if (event.getItem().getItemMeta().getDisplayName().equals("§e选择服务器 §7(右键打开)")){
                event.getPlayer().chat("/menu");
            } else if (event.getItem().getItemMeta().getDisplayName().equals("§e个人信息 §7(右键打开)")){
                event.getPlayer().chat("/profile");
            } else if (event.getItem().getItemMeta().getDisplayName().equals("§e游戏商店 §7(右键打开)")){
                event.getPlayer().chat("/shop");
            } else if (event.getItem().getItemMeta().getDisplayName().equals("§e大厅选择器 §7(右键打开)")){
                event.getPlayer().chat("/select");
            } else if (event.getItem().getItemMeta().getDisplayName().equals("§e提出建议 §7(右键打开)")){
                event.getPlayer().chat("/issue");
            } else if (event.getItem().getItemMeta().getDisplayName().equals("§e收集箱 §7(右键打开)")){
                event.getPlayer().chat("/collection");
            }
        }
    }

    @EventHandler
    public void onPlayerMoveGeneralItem(InventoryClickEvent event){
        Player player = (Player) event.getWhoClicked();
        if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null && event.getCurrentItem().getItemMeta().getDisplayName() != null){
            if (event.getCurrentItem().getItemMeta().getDisplayName().startsWith("§e")) {
                event.setCancelled(true);
            }
        }
    }

    @EventHandler
    public void onEditBook(PlayerEditBookEvent event){
        event.setCancelled(true);
    }
}







